package com.liuqi.phone.design

import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.support.v7.app.ActionBarDrawerToggle
import android.view.Menu
import com.liuqi.phone.design.utils.StatusBarUtil2
import kotlinx.android.synthetic.main.activity_main.*

class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        initToobar()
        initDrawer()

    }

    private fun initToobar() {
        StatusBarUtil2.setPaddingSmart(this,toolbar)
        setSupportActionBar(toolbar)
    }

    override fun onCreateOptionsMenu(menu: Menu?): Boolean {
        menuInflater.inflate(R.menu.toobar_search,menu)
        return true
    }

    private fun initDrawer() {
        drawer.run {
            var toggle = ActionBarDrawerToggle(
                    this@MainActivity
                    ,this,
                    toolbar,
                    R.string.navigation_drawer_open,
                    R.string.navigation_drawer_close)
            //实现toolbar和Drawer的联动：
            toggle.syncState()
            addDrawerListener(toggle)
        }
    }

    override fun onBackPressed() {
        if (drawer.isDrawerOpen(navigation)) {
            drawer.closeDrawers()
            return
        }
        super.onBackPressed()
    }
}
